# -*- coding: utf-8 -*-
# @Author:Thl
# @Time: 2019/4/18

import time
from selenium import webdriver

qzoneUrl = 'https://ui.ptlogin2.qq.com/cgi-bin/login?pt_hide_ad=1&style=9&pt_ttype=1&appid=549000929&pt_no_auth=1&pt_wxtest=1&daid=5&s_url=https%3A%2F%2Fh5.qzone.qq.com%2Fmqzone%2Findex'
myQQ = input("请输入你的账号：")
myPassword = input("请输入你的密码：")

driver = webdriver.Chrome()  # 打开本地谷歌浏览器
driver.maximize_window()  # 窗口最大化
driver.get(qzoneUrl)  # 访问qq空间登录页面

driver.implicitly_wait(30)  # 隐等待

driver.find_element_by_name('u').clear()  # 清空账号input框
driver.find_element_by_name('u').send_keys(myQQ)  # 输入账号
driver.find_element_by_name('p').clear()  # 清空密码input框
driver.find_element_by_name('p').send_keys(myPassword)  # 输入密码
driver.find_element_by_id('go').click()  # 点击登录按钮

time.sleep(5)
# 等待，可能会有验证，需要手动操作

while 1:
    time.sleep(5)
    try:
        btns = driver.find_elements_by_class_name('like')  # 寻找赞按钮
        for btn in btns:
            if btn.text == '赞':
                time.sleep(3)
                btn.click()  # 点赞
                print('liked')
            else:
                continue
    except:
        print("error")
        driver.refresh()
        time.sleep(2)
        break
    driver.refresh()
    time.sleep(60)  # 每60秒一次刷新

driver.close()